package logic

import (
	"context"
	"fmt"
	"order_srv/internal/svc"
	"order_srv/model/mysql"
	"order_srv/order"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateOrderLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCreateOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateOrderLogic {
	return &CreateOrderLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CreateOrderLogic) CreateOrder(in *order.CreateOrderRequest) (*order.CreateOrderResponse, error) {

	m := mysql.Order{
		UserId:  in.UserId,
		OrderSn: in.OrderSn,
		Amount:  in.Amount,
		Payment: in.Payment,
	}
	err := m.CreateOrder()
	if err != nil {
		fmt.Println("添加失败")
		return nil, err
	}
	return &order.CreateOrderResponse{}, nil
}
